var skill = {
	//获取已经抽过奖的活动以及中奖信息
	getLotteryList: function() {
		var lottery_list = this.lottery_list;
		if (!Array.isArray(lottery_list)) {
			lottery_list = this.lottery_list = [];
			this.save();
		}
		return lottery_list;
	},
	getLotteryDetailList: function(filter) {
		var bus_id = filter.bus_id;
		var state = parseInt(filter.state);


		var lottery_list = this.getLotteryList().map(function(lottery_info) {
			var res = $Object.clone(lottery_info);
			res.lottery = BusLotteryCon.get(lottery_info.lottery_id)
			return res;
		});
		if (bus_id) {
			lottery_list = lottery_list.filter(function(lottery_info) {
				return lottery_info.lottery.bus_id === bus_id;
			});
		}
		if (isFinite(state)) {
			lottery_list = lottery_list.filter(function(lottery_info) {
				return lottery_info.lottery.state === state;
			});
		}
		return lottery_list;
	},
	//只能领取增加，不可删除不可修改
	drawLottery: function(bus_id, lottery_id) {
		var bus = BusCon.get(bus_id);
		if (!bus) {
			throwCusError("找不到指定商家")
		}
		var lottery = bus.getLottery(lottery_id);
		var win_something = lottery._addJoinNumber(this._id);

		var lottery_list = this.getLotteryList();
		lottery_list.push({
			lottery_id: lottery_id,
			win: win_something
		});
		this.save();
		/*根据中奖信息进行相应领奖操作*/
		if (win_something) {
			switch (win_something.type) {
				case BusLotteryCon.TYPE.优惠券:
					bus.sendTicketFactoryToUserTicket(this._id, win_something.content_id)
					break;
			}
		}
		return win_something || null /*null可用于JSON化，所以不用undefined*/ ;
	}
};
module.exports = skill;
var db = require("../db/index");
var CouponCon = require("../coupon/_con");
var TicketCon = require("../ticket/_con");
var TicketFactoryCon = require("../ticket_factory/_con");
var DomainCon = require("../domain/_con");
var GoodsCon = require("../goods/_con");
var UserCon = require("../../core/user/_con");
var BusCon = require("../../core/bus/_con");
var AchCon = require("../ach/_con");
var ClassifyCon = require("../bus.classify/_con");
var BusLotteryCon = require("../bus.lottery/_con");
var TagCon = require("../bus.tag/_con");
var LeagueCon = require("../league/_con");
var BuffCon = require("../buff/_con");
var BusUserBindCon = require("../bus_user_bind/_con");
var BusGuideCon = require("../bus.guide/_con");
var CommentCon = require("../comment/_con");
var config = require("../_include/config");
var data_cut = require("../_include/data_cut");
var helper = require("../_include/helper");
var md5 = require("../_include/md5");
var $Object = require("../_include/$.Object");
var $Array = require("../_include/$.Array");
var tld = require('tldjs');
var fs = require("fs");
var Fiber = require('fibers');